package com.shujia.mysql;

import java.sql.*;

public class mysqlConnect {
    static final String DRIVER = "com.mysql.jdbc.Driver";
    static final String URL = "jdbc:mysql://master:3306/shujia";
    static final String USER = "root";
    static final String PASSWORD = "123456";

    public static void main(String[] args) throws Exception {
        //加载驱动
        Class.forName(DRIVER);
        //获取连接
        Connection conn=DriverManager.getConnection(URL,USER,PASSWORD);
        //执行查询
        Statement statement = conn.createStatement();
        String test=" 'SMITH1 ' or 1=1 ";
        String sql="select * from emp where ename="+test;
        System.out.println(sql);
        //获取结果
        ResultSet resultSet = statement.executeQuery(sql);
        //展开结果
        while(resultSet.next()){
            int id=resultSet.getInt("empno");
            String name=resultSet.getString("ename");
            Date hiredate = resultSet.getDate("hiredate");
            System.out.println(id+"---"+name+"----"+hiredate);
        }


//		String sql="insert into student(name,age,sex)values('你猜',18,'男')";
//		ps=conn.prepareStatement(sql);
//		ps.executeUpdate();


//		String sql="insert into student(name,age,sex) values(?,?,?)";
//		getConnection();
//		ps=conn.prepareStatement(sql);
//		ps.setString(1, "杨帅");
//		ps.setString(2, 18);
//		ps.setString(3, "男");
//		count=ps.executeUpdate();

        resultSet.close();
        statement.close();
        conn.close();
    }
}
